home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / games / dissociate.el.z / dissociate.el
Encoding:
Text File  |  1998-05-21  |  3.2 KB  |  104 lines

  1. ;;; dissociate.el --- scramble text amusingly for Emacs.
  2.  
  3. ;; Copyright (C) 1985 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6. ;; Keywords: games
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  22. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  23. ;; 02111-1307, USA.
  24.  
  25. ;;; Synched up with: FSF 19.34.
  26.  
  27. ;;; Commentary:
  28.  
  29. ;; The single entry point, `dissociated-press', applies a travesty
  30. ;; generator to the current buffer.  The results can be quite amusing.
  31.  
  32. ;;; Code:
  33.  
  34. ;;;###autoload
  35. (defun dissociated-press (&optional arg)
  36.   "Dissociate the text of the current buffer.
  37. Output goes in buffer named *Dissociation*,
  38. which is redisplayed each time text is added to it.
  39. Every so often the user must say whether to continue.
  40. If ARG is positive, require ARG chars of continuity.
  41. If ARG is negative, require -ARG words of continuity.
  42. Default is 2."
  43.   (interactive "P")
  44.   (setq arg (if arg (prefix-numeric-value arg) 2))
  45.   (let* ((inbuf (current-buffer))
  46.      (outbuf (get-buffer-create "*Dissociation*"))
  47.      (move-function (if (> arg 0) 'forward-char 'forward-word))
  48.      (move-amount (if (> arg 0) arg (- arg)))
  49.      (search-function (if (> arg 0) 'search-forward 'word-search-forward))
  50.      (last-query-point 0))
  51.     (if (= (point-max) (point-min))
  52.     (error "The buffer contains no text to start from"))
  53.     (switch-to-buffer outbuf)
  54.     (erase-buffer)
  55.     (while
  56.       (save-excursion
  57.     (goto-char last-query-point)
  58.     (vertical-motion (- (window-height) 4))
  59.     (or (= (point) (point-max))
  60.         (and (progn (goto-char (point-max))
  61.             (y-or-n-p "Continue dissociation? "))
  62.          (progn
  63.            (message "")
  64.            (recenter 1)
  65.            (setq last-query-point (point-max))
  66.            t))))
  67.       (let (start end)
  68.     (save-excursion
  69.      (set-buffer inbuf)
  70.      (setq start (point))
  71.      (if (eq move-function 'forward-char)
  72.          (progn
  73.            (setq end (+ start (+ move-amount (random 16))))
  74.            (if (> end (point-max))
  75.            (setq end (+ 1 move-amount (random 16))))
  76.            (goto-char end))
  77.        (funcall move-function
  78.             (+ move-amount (random 16))))
  79.      (setq end (point)))
  80.     (let ((opoint (point)))
  81.       (insert-buffer-substring inbuf start end)
  82.       (save-excursion
  83.        (goto-char opoint)
  84.        (end-of-line)
  85.        (and (> (current-column) fill-column)
  86.         (do-auto-fill)))))
  87.       (save-excursion
  88.        (set-buffer inbuf)
  89.        (if (eobp)
  90.        (goto-char (point-min))
  91.      (let ((overlap
  92.         (buffer-substring (prog1 (point)
  93.                      (funcall move-function
  94.                           (- move-amount)))
  95.                   (point))))
  96.        (goto-char (1+ (random (1- (point-max)))))
  97.        (or (funcall search-function overlap nil t)
  98.            (let ((opoint (point)))
  99.          (goto-char 1)
  100.          (funcall search-function overlap opoint t))))))
  101.       (sit-for 0))))
  102.  
  103. ;;; dissociate.el ends here
  104.